<?php

include "header.php";
include "./lib/func.php";
include "./lib/config.php";

if (($user = isLogin()) == false){
    header("location:index.php");
    exit;
}

$body = getPost('status');
if (!$body){
    showError('内容不能为空');
}

$redis = connentRedis(Config::REDISHOST, Config::PORT);
$postid = $redis->incr('global:postid');
//发微博并推给粉丝
$redis->set('post:postid:'. $postid. ':time', time());
$redis->set('post:postid:'. $postid. ':userid', $user['userid']);
$redis->set('post:postid:'. $postid. ':body', $body);

$myFans = $redis->sMembers('followed:'. $user['userid']);
$myFans[] = $user['userid'];

foreach ($myFans as $myFanId) {
    $redis->lPush('recivePost:'. $myFanId, $postid);
}


header("location:home.php");

include "footer.php";